package com.example.lvsuo.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.example.lvsuo.entity.Notebook;
import com.example.lvsuo.modal.Result;
import com.example.lvsuo.service.INotebookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 笔记本 前端控制器
 * </p>
 *
 * @author 心心念念
 * @since 2021-03-30
 */
@RestController
@RequestMapping("/notebook")
public class NotebookController {
    @Autowired
    INotebookService ns;

    /**
     * 添加
     * @param n
     * @return
     */
    @PostMapping
    Result addNote(Notebook n){
        ns.save(n);
        return Result.back("成功");
    }

    /**
     * 查询
     * @return
     */
    @GetMapping
    Result queryNote(String id){
        return Result.back(ns.list(new QueryWrapper<Notebook>().eq("user_id",id)));
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @DeleteMapping
    Result deNote(String date){
        ns.remove(new UpdateWrapper<Notebook>().eq("date",date));
        return Result.back("成功");
    }
}

